<div class="alert alert-success alert-dismissable">
    <button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button>
    <%- message %>

</div>
<div class="panel panel-info">
<div class="panel-heading"><h4 class="panel-title">组管理</h4></div>
<form action="/groups/upsert/<%=_id?_id:'nil'%>" method="post" class="form-horizontal" id="uform" role="form">
    <div class="form-group">
        <label for="inputEmail3" class="col-sm-2 control-label">组名称</label>

        <div class="col-sm-10">
            <input type="text" class="form-control" name="name" placeholder="Email">
        </div>
    </div>
    <div class="form-group">
        <label for="inputPassword3" class="col-sm-2 control-label">说明</label>

        <div class="col-sm-10">
            <textarea class="form-control" name="remark"></textarea>
        </div>
    </div>
    <div class="form-group">
        <label for="inputPassword3" class="col-sm-2 control-label">具有权限</label>

        <div class="col-sm-10">
            <table class="table table-hover table-striped  table-condensed">
               <caption>请设置权限</caption>
                <thead>
                 <tr>
                   <td>
                      <input type="checkbox" onclick="checkOrnot(event)">
                   </td>
                   <td></td>
                   <td></td>
                   <td></td>
                   <td></td>

                 </tr>

                </thead>
                <tbody id="auths">
               </tbody>
            </table>
        </div>
    </div>
    <div class="form-group">
        <div class="col-sm-offset-2 col-sm-10">
            <button type="submit" class="btn btn-default">保存</button>
        </div>
    </div>

</form>
</div>
 <script>
     var beans = <%-beans%>;
     $(function(){
         $.getJSON('/webrest/jsonall',function(data){

             var tbody = $("#auths");
             tbody.empty();
             var tr = null;
             for(var i=0;i<data.length;i++){
                 if(i%5==0){
                     tr = $("<tr></tr>");
                     tbody.append(tr);
                 }
                 var chk=$("<input type='checkbox' >");
                 chk.attr("name","webrests["+i+"]")
                 chk.val(data[i]._id);
                 var chklabel = $("<label></label>").append(chk).append(data[i].name);
                 var td = $("<td></td>").append(chklabel);
                 tr.append(td);

             }

             $("form#uform").helpform({'beans':beans});
         });

     });

     function checkOrnot(event){
        var chkable =  $(event.target).prop("checked")
        if(chkable){
            $("#auths :checkbox").prop("checked",true);
        }else{
            $("#auths :checkbox").prop("checked",false);
        }
     }
 </script>

